package org.agridata.akvisualization.page;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.io.Serializable;
import java.util.List;

/**
 * 表格分页数据对象
 *
 * @author zhuhs
 */
public class PageData<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 总记录数
     */
    private Long total;

    /**
     * 列表数据
     */
    private List<T> rows;

    /**
     * 当前页
     */
    private Long current;

    /**
     * 总页数
     */
    private Long pages;


    /**
     * 表格数据对象
     */
    public PageData() {
    }

    /**
     * 分页
     *
     * @param list  列表数据
     * @param total 总记录数
     */
    public PageData(List<T> list, Long total) {
        this.rows = list;
        this.total = total;
    }

    public PageData(Long total, List<T> rows, Long current, Long pages) {
        this.total = total;
        this.rows = rows;
        this.current = current;
        this.pages = pages;
    }


    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Long getCurrent() {
        return current;
    }

    public void setCurrent(Long current) {
        this.current = current;
    }

    public Long getPages() {
        return pages;
    }

    public void setPages(Long pages) {
        this.pages = pages;
    }

    public Long getTotal() {
        return total;
    }

    public PageData<T> restPage(Page page, List voList) {
        this.setRows(voList);
        this.setPages(page.getPages());
        this.setCurrent(page.getCurrent());
        this.setTotal(page.getTotal());
        return this;
    }

    public PageData<T> restPage(Page page) {
        this.setRows(page.getRecords());
        this.setPages(page.getPages());
        this.setCurrent(page.getCurrent());
        this.setTotal(page.getTotal());
        return this;
    }
}